<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="../common/header.jsp" %>
<div class="container-fluid p-t-15">
  <div class="row">
    <div class="col-lg-12">
      <div class="card">
        <div class="card-body">
          
          <form action="#" onsubmit="return false;" method="post" class="row" id="save-form">
            <div class="form-group col-md-12">
              <label for="type">所属角色</label>
              <div class="form-controls">
                <select name="role_id" class="form-control" id="role_id" required>
                  <option value="0">请选择角色</option>
				  <c:forEach items="${requestScope.role}" var="a">
				  <c:choose>
				  <c:when test="${admin.role_id==a.id}">
					<option value="${a.id}" selected>${a.name}</option>
				  </c:when>
				  <c:otherwise>
					<option value="${a.id}">${a.name}</option>
				  </c:otherwise>
				  </c:choose>
				  </c:forEach>
                </select>
              </div>
            </div>
			
            <div class="form-group col-md-12">
              <label for="name">用户名称</label>
              <input type="text" class="form-control" id="username" name="username" value="${admin.username}" placeholder="请输入用户名称" required />
            </div>
			
			<div class="form-group col-md-12">
              <label for="url">用户密码</label>
              <input type="password" class="form-control" id="password" name="password" value="" placeholder="请输入用户密码"/>
            </div>
			
            <div class="form-group col-md-12">
              <label for="status">状态</label>
              <div class="clearfix">
				<label class="lyear-radio radio-inline radio-primary">
					<c:choose>
					<c:when test="${admin.status==1}">
					<input type="radio" name="status" value="1" checked><span>启用</span>
					</c:when>
					<c:otherwise>
					<input type="radio" name="status" value="1"><span>启用</span>
					</c:otherwise>
					</c:choose>
                </label>
                <label class="lyear-radio radio-inline radio-primary">
					<c:choose>
					<c:when test="${admin.status==0}">
					<input type="radio" name="status" value="0" checked><span>禁用</span>
					</c:when>
					<c:otherwise>
					<input type="radio" name="status" value="0"><span>禁用</span>
					</c:otherwise>
					</c:choose>
                </label>
              </div>
            </div>
			
            <div class="form-group col-md-12">
			  <input type="hidden" name="id" value="${admin.id}"/>
              <button type="submit" class="btn btn-primary ajax-post btn-sm">确 定</button>
              <button type="button" class="btn btn-default btn-sm" onclick="javascript:history.back(-1);return false;">返 回</button>
            </div>
          </form>
 
        </div>
      </div>
    </div>
    
  </div>
</div>
<%@ include file="../common/footer.jsp"%>
<script type="text/javascript">
	$("#save-form").validate({
		messages: {
			"username": {
				required: '请输入用户名称'
			}
		},
		submitHandler: function(form) {
			save();
		}
	});
	function save(){
		lightyear.loading('show');
		setTimeout(function () {
			$.ajax({
				type: "POST",//方法类型
				url: "${pageContext.request.contextPath}/admin/admin?method=doEdit",
				data: $('#save-form').serialize(),
				dataType: 'json',
				success: function (result) {
					if (result.code == 200) {
						lightyear.notify(result.message, 'success', 3000);
						window.location.href="${pageContext.request.contextPath}/admin/admin?method=List";
					} else {
						lightyear.notify(result.message, 'danger', 3000);
					}
				},
				error: function (XMLHttpRequest, textStatus, errorThrown) {
					lightyear.notify('对不起，失败', 'danger', 3000);
				},
				complete: function () {
					lightyear.loading('hide');
				}
			});
		}, 1e3);
	}
</script>